home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 235_01 / ovcmd.c < prev    next >
Text File  |  1987-06-16  |  4KB  |  121 lines

  1. /*  016  24-Jan-87  ovcmd.c
  2.  
  3.         Copyright (c) 1987 by Blue Sky Software.  All rights reserved.
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <process.h>
  8. #include "ov.h"
  9.  
  10. extern WINDOW cw;
  11. extern FILE_ENT files[];
  12.  
  13. char *strrchr();
  14.  
  15.  
  16. /******************************************************************************
  17.  **                         D O _ C M D                                      **
  18.  *****************************************************************************/
  19.  
  20. do_cmd() {             /* read and execute a single dos command */
  21.  
  22.    char *cmd;
  23.  
  24.    cmd = prompt("","Enter a single DOS command to execute",NULL,0,MAX_REPLY);
  25.    if (strlen(cmd) == 0)
  26.       return;
  27.  
  28.    run_cmd(cmd,TRUE);                  /* execute the command */
  29. }
  30.  
  31.  
  32. /******************************************************************************
  33.                              E X E C U T E
  34.  ******************************************************************************/
  35.  
  36. execute() {            /* execute the current file */
  37.  
  38.    char title[MAX_NAMELEN+10], *fn, *ext, *cmd, *fnbuf;
  39.  
  40.    /* make sure the file looks like its executable */
  41.  
  42.    if (files[cw.curidx].flags & DIR)
  43.       show_error(0,11,1,"Can't execute a directory!");
  44.  
  45.    if ((ext = strrchr(fn = files[cw.curidx].name,'.')) == NULL ||
  46.        strlen(ext) < 4 || strstr(".EXE .COM .BAT",ext) == NULL)
  47.       show_error(0,11,2,fn,
  48.                  " does not have a EXE, COM, or BAT extension, can't execute!");
  49.  
  50.    fnbuf = fname(&files[cw.curidx]);   /* put cmd less ext into bufers */
  51.    *strrchr(fnbuf,'.') = '\0';
  52.    strcpy(title,"Execute ");
  53.    strcat(title,fn);
  54.  
  55.    cmd = prompt(title,"Add parameters to command, return to execute.",
  56.          fnbuf,strlen(fnbuf)+1,MAX_REPLY);
  57.  
  58.    free(fnbuf);                        /* free fname() space */
  59.  
  60.    if (strlen(cmd) == 0)               /* user can cancel by clearing line */
  61.       return;
  62.  
  63.    run_cmd(cmd,TRUE);                  /* run the command */
  64. }
  65.  
  66.  
  67. /******************************************************************************
  68.  **                          R U N _ C M D                                   **
  69.  *****************************************************************************/
  70.  
  71. run_cmd(cmd,pause)     /* execute a dos command via command.com */
  72. char *cmd;
  73. int pause;
  74. {
  75.  
  76.    clr_scr();                          /* home the cursor and clear screen */
  77.    showcursor();                       /* let user see the cursor */
  78.  
  79.    system(cmd);                        /* do the DOS command */
  80.  
  81.    if (pause) {
  82.       putstr("\r\nPress any key to return to OVERVIEW.");
  83.       getchr();
  84.    }
  85.  
  86.    /* who knows what state things might be after a DOS command, restart
  87.       everything from scratch */
  88.  
  89.    reinit_tty();                       /* make sure the tty is setup right */
  90.    renew();                            /* renew the screen, etc */
  91. }
  92.  
  93.  
  94. /******************************************************************************
  95.  **                      S P A W N _ C L I                                   **
  96.  *****************************************************************************/
  97.  
  98. void
  99. spawn_cli() {          /* spawn a copy of the command interpeter */
  100.  
  101.    char comspec[MAX_PATHLEN+1], *ep, *getenv();
  102.  
  103.    clr_scr();                          /* home cursor, clear screen */
  104.    showcursor();                       /* show user the cursor */
  105.  
  106.    putstr("\r\nEnter the command 'EXIT' to return to OVERVIEW.\r\n");
  107.  
  108.    if (ep = getenv("COMSPEC"))         /* use COMSPEC env variable if defined */
  109.       strcpy(comspec,ep);
  110.    else
  111.       strcpy(comspec,"\COMMAND.COM");  /* otherwise hope its in the root dir */
  112.  
  113.    spawnl(P_WAIT,comspec,NULL);        /* run a copy of command.com */
  114.  
  115.    /* who knows what state things might be after going to DOS, restart
  116.       everything from scratch */
  117.  
  118.    reinit_tty();                       /* make sure tty is setup right */
  119.    renew();                            /* renew screen, etc */
  120. }
  121.